package jdbc;

import java.sql.*;

/**
 * 将article表中的数据查询出来并输入到控制台
 */
public class Test04 {
    public static void main(String[] args) {
        /*
            SELECT id,title,content FROM article;
         */
        try (Connection connection = DBUtil.getConnection()){
            String sql = "SELECT id,title,content FROM article;";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            System.out.println("开始查询");
            while (rs.next()){
                int id = rs.getInt("id");
                String title = rs.getString("title");
                String content = rs.getString("content");
                System.out.println("文章"+id+": "+title+": "+content);
            }
            System.out.println("查询完毕");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
